﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Webadmin_Modules_NewsOne_CateEdit : bzAdminUCBase
{
    public string _Act = "";
    public string _ID = "";
    public DataTable _dt = new DataTable();
    public bzServiceCate bz = new bzServiceCate();
    public DataRow dr = null;
    override protected void loadAction()
    {
        _Act = Request.QueryString["Act"] == null ? "" : Request.QueryString["Act"];
        _ID = Request.QueryString["ID"] == null ? "-1" : Request.QueryString["ID"];
        _dt = bz.getRecord(_ID, "-1");
        if (_dt.Rows.Count > 0)
        {
            dr = _dt.Rows[0];
        }
        if (!IsPostBack)
        {
            switch (_Act)
            {
                case "Edit": this.loadEdit(); break;
                case "Add": this.resetData(); break;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang(bzSiteOption.Group.Administrator, bzSiteOption.Note.NewsOne, "NewsOne");
    }
    private void loadEdit()
    {
        this.Navigator = this.AdminLang["Menuservices"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["MenuServiceCate"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["Edit"].ToString();
        this.btnUpdate.Text = this.AdminLang["Edit"].ToString();

        _dt = bz.getRecord(_ID);
        DataRow dr = _dt.Rows[0];
        this.txtNameVN.Text = dr["NameVN"].ToString();
        this.txtNameEN.Text = dr["NameEN"].ToString();
       // this.cboCategory.SelectedValue = dr["PrentID"].ToString();
        this.rdForward_1.Enabled = false;
        this.rdForward_0.Checked = true;
        this.rdEnabled_1.Checked = Convert.ToInt16(dr["Enabled"]) <= 0 ? false : true;
        this.rdEnabled_0.Checked = !this.rdEnabled_1.Checked;
    }

    private void resetData()
    {
        this.Navigator = this.AdminLang["Menuservices"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["MenuServiceCate"].ToString() + this.AdminLang["GeneralArrow"].ToString() + this.AdminLang["AddNew"].ToString();
        this.txtNameVN.Text = "";
        this.txtNameEN.Text = "";

        this.rdForward_0.Checked = false;
        this.rdForward_1.Checked = !this.rdForward_0.Checked;
        this.btnUpdate.Text = this.AdminLang["AddNew"].ToString();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        switch (_Act)
        {
            case "Edit": this.editImage(); break;
            case "Add": this.insertImage(); break;
        }
    }
    private void editImage()
    {
        DataTable dtTmp = bz.getRecord(_ID);
        
            if (bz.updateRecord(_ID, this.txtNameVN.Text, this.txtNameEN.Text, this.rdEnabled_0.Checked ? "0" : "1", "-1") > 0)
            {
                Response.Write(bzStringClass.addStringAlert(this.AdminLang["Success"]));
                Response.Write(bzStringClass.redirectClient(Session["Page"].ToString()));
            }
       
    }
    private void insertImage()
    {

        if (bz.insertRecord(this.txtNameVN.Text, this.txtNameEN.Text, this.rdEnabled_0.Checked ? "0" : "1", "-1") > 0)
        {
            if (this.rdForward_0.Checked)
            {
                Response.Write(bzStringClass.addStringAlert(this.AdminLang["Success"]));
                Response.Write(bzStringClass.redirectClient(Session["Page"].ToString()));
            }
            else this.resetData();
        }
    }
}
